﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ppt_outliner
{
    public partial class Form1 : Form
    {
        private SlideTree slideTree;

        public Form1()
        {
            InitializeComponent();

            // 创建并添加SlideTree控件
            slideTree = new SlideTree();
            slideTree.Dock = DockStyle.Fill;
            this.Controls.Add(slideTree);

            // 设置窗体属性
            this.Text = "PPT大纲视图";
            this.Width = 300;
            this.Height = 600;
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new System.Drawing.Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, 0);
            this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
            this.TopMost = true;  // 保持窗口在最前

            // 处理窗体关闭事件
            this.FormClosing += Form1_FormClosing;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;  // 取消关闭
                this.Hide();      // 隐藏窗体而不是关闭
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            // 在这里可以添加窗体加载时的初始化代码
        }

        public void RefreshTree()
        {
            if (!this.IsDisposed && slideTree != null && !slideTree.IsDisposed)
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new Action(RefreshTree));
                    return;
                }

                try
                {
                    slideTree.RefreshTree();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"刷新树视图失败: {ex.Message}");
                }
            }
        }
    }
}
